<template>
    <div class="list">
       <img :src="item.img" alt="">
       <h5>{{item.name}}</h5>
       <button @click="add(item)">添加</button>
    </div>
</template>
<script>
export default {
    props:['item'],
    methods: {
        add(item){
            // 判重
         let flag = this.$store.state.bookList.some(it=>it.id == item.id)
         if(flag){
            alert('重复了')
            return
         }
            this.$store.commit('addBook',item)
        }
    },
}
</script>
<style lang="scss" scoped>
.list{
    width:50%;
    img{
        width:100%;
        height:200px;
    }
}
</style>

